<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
    	<base href="<%=basePath%>">
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/font.css">
        <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/xadmin.css">
        <script type="text/javascript" src="<%=basePath %>leyuiyc/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<%=basePath %>leyuiyc/js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>增加打包商品</legend>
	</fieldset>
	<form class="layui-form">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">打包商品名称</label>
				<div class="layui-input-inline">
					<input type="text" name="baleGoodName" lay-verify="required"
						lay-reqtext="商品名称是必填项，岂能为空？" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">打包商品价格</label>
				<div class="layui-input-inline">
					<input type="text" name="baleGoodPrice" placeholder="请输入两位小数"
						lay-verify="baleGoodPrice" lay-reqtext="商品价格必填项，岂能为空？"
						class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">打包商品数量</label>
				<div class="layui-input-inline">
					<input type="text" name="baleAmount" placeholder="请输入正整数"
						lay-verify="baleAmount" lay-reqtext="商品数量是必填项，岂能为空？"
						class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">预售数量</label>
				<div class="layui-input-inline">
					<input type="text" name="balePresaleNum" placeholder="请输入正整数"
						lay-verify="balePresaleNum" lay-reqtext="打包商品预售数量是必填项，岂能为空？"
						class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">有效期</label>
				<div class="layui-input-block">
					<input class="layui-input" name="baleGoodValidity" id="newdate"
						lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off">
				</div>
			</div>
			&emsp;&emsp;&emsp;
		<div class="layui-inline">
      				<label class="layui-form-label">商品状态</label>
			      <div class="layui-input-inline">
			        <select name="status" lay-verify="required"  lay-search="">
			        	<option value="">请选择</option>
			          <option value="0" >下架</option>
			          <option value="1" >上架</option>
			        </select>
				      </div>
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <div class="layui-inline">
				      <label class="layui-form-label">赠送积分</label>
				      <div class="layui-input-inline">
				        <input type="text" name="awardedIntegral" placeholder="请输入正整数"  lay-verify="awardedIntegral" lay-reqtext="赠送积分是必填项，岂能为空？"  class="layui-input">
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">能否积分兑换</label>
				      <div class="layui-input-inline">
				        <select name="integralBuy" lay-verify="required"  lay-search="" >
				        	<option value="">请选择</option>
			          		<option value="0" >不能</option>
			          		<option value="1" >能</option>
			        	</select>
				      </div>
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <div class="layui-inline">
				      <label class="layui-form-label">兑换所需积分</label>
				      <div class="layui-input-inline">
				        <input type="text" name="goodsExchIntegral" placeholder="请输入正整数"  lay-verify="goodsExchIntegral"  lay-reqtext="必填项，岂能为空？"  class="layui-input">
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">运费</label>
				      <div class="layui-input-inline">
				        <input type="text" name="shippingFee"  placeholder="请输入两位小数"  lay-verify="shippingFee" lay-reqtext="运费是必填项，岂能为空？"  class="layui-input">
				      </div>
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <div class="layui-inline">
				      <label class="layui-form-label">是否可以退货</label>
				      <div class="layui-input-inline">
				      	 <select name="goodsRefund" lay-verify="required" lay-search="">
				      	 	<option value="">请选择</option>
			          		<option value="0" >不能</option>
			          		<option value="1" >能</option>
			        	</select>
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">商品分类</label>
				      <div class="layui-input-inline">
				      	 <select name="gcid" lay-verify="required" lay-search="">
				      	 	<option value="">请选择</option>
			          		<option value="0" >不能</option>
			          		<option value="1" >能</option>
			        	</select>
				      </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				    <div class="layui-inline">
				      <label class="layui-form-label">创建时间</label>
				      <div class="layui-input-block">
						<input class="layui-input" name="creatTime" id="newdate2"
							lay-verify="required" readonly="readonly" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off">
					</div>
				    </div>
				    &emsp;&emsp;&emsp;
				    <div class="layui-inline">
				      <label class="layui-form-label">退货费用</label>
				      <div class="layui-input-inline">
				        <input type="text" name="returnFee" placeholder="请输入两位小数"  lay-verify="returnFee"  value="0.00" class="layui-input">
				      </div>
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <div class="layui-inline">
				      <label class="layui-form-label">创建人ID</label>
				      <div class="layui-input-inline">
				      	<input type="text" name="createUserId" readonly="readonly" placeholder="请输入正整数"  lay-verify="createUserId" value="${userinfo.userId }" class="layui-input">
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">创建人姓名</label>
				      <div class="layui-input-inline">
				        <input type="text" name="createUserName" readonly="readonly" lay-verify="required" value="${userinfo.userName }" class="layui-input">
				      </div>
				    </div>
				  </div>
					<div class="layui-form-item">
						<div class="layui-form-item layui-form-text">
							<label class="layui-form-label">打包商品介绍</label>
							<div class="layui-input-block">
								<textarea placeholder="请输入内容" lay-verify="required" class="layui-textarea"></textarea>
							</div>
						</div>
					</div>
		<div class="layui-form-item">
				  		<input class="fileupload-input" id="gcPicpath" lay-verify="picpath" type="hidden" name="picpath" />
				  </div>
				  <div class="layui-form-item">
				  		<input class="fileupload-input" id="infoPicPath" type="hidden" lay-verify="infoPicPath" name="infoPicPath" />
				  </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                      &emsp;&emsp;&emsp;  <button class="layui-btn" lay-filter="add" lay-submit="">保  &emsp;&emsp;  存</button>
                     </div>
                </form>
                <div class="layui-form-item" style="position: absolute;top: 100px;left: 850px;" >
						<button class="layui-btn layui-btn-danger layui-btn-radius" id="editimg1">上传商品图片</button >
				 </div>
				 	<div style="height:400px;width:400px;position: absolute;top: 150px;left: 750px;">
				 		<img alt="" id="img" src="">
				 		</div>
				 	
        <script >
				layui.use(['form','slider','layedit', 'laydate', "jquery"], function(){
				  var form = layui.form
				  ,layer = layui.layer
				  ,layedit = layui.layedit
				  ,laydate = layui.laydate
				  ,slider = layui.slider
				  ,$ = layui.jquery;
				  
				  var day1 = new Date();
				  var storage = window.sessionStorage;
				  var array = storage.getItem("array");
				  
				  console.log(array);
				  //日期
				  laydate.render({
				    elem: '#newdate'
				    ,trigger: 'click'
				  });
				   //日期
				  laydate.render({
				    elem: '#newdate2'
				    ,trigger: 'click'
				    ,format: 'yyyy-MM-dd HH:mm:ss'
				    ,value: day1
				  });
				  //监听提交
				  form.on('submit(add)', function(data){
				  	var field = data.field;
				  	$.ajax({
                    	url:"BaleGoods/addBaleGoods.do",
                    	method:"post",
                    	data:{"baleGoodName":field.baleGoodName
                    	,"baleGoodPrice":field.baleGoodPrice
                    	,"baleAmount":field.baleAmount
                    	,"balePresaleNum":field.balePresaleNum
                    	,"baleGoodValidity":field.baleGoodValidity
                    	,"status":field.status
                    	,"awardedIntegral":field.awardedIntegral
                    	,"integralBuy":field.integralBuy
                    	,"goodsExchIntegral":field.goodsExchIntegral
                    	,"goodsRefund":field.goodsRefund
                    	,"shippingFee":field.shippingFee
                    	,"gcid":field.gcid
                    	,"createUserId":field.createUserId
                    	,"createUserName":field.createUserName
                    	,"creatTime":field.creatTime
                    	,"returnFee":field.returnFee
                    	,"picpath":field.picpath
                    	,"infoPicPath":field.infoPicPath
                    	},
                    	dataType:"json",
                    	success:function(data){
                    		storage.removeItem('array');
                    		layer.msg('添加成功！', {icon: 6}); 
                    	}
                    	})
				    return false;
				  });
				  //自定义验证规则
				  form.verify({
				  goodsExchIntegral: [
				      /^\d+$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,createUserId: [
				      /^\d+$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]			
					,commonGoodsId: [
				      /^\d+$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]				  
				    ,baleAmount: [
				      /^\d+$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,shippingFee: [
				      /^[0-9]+(\.[0-9]{2})?$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,baleGoodPrice: [
				      /^[0-9]+(\.[0-9]{2})?$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,baleGoodsPrice: [
				      /^[0-9]+(\.[0-9]{2})?$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,returnFee: [
				      /^[0-9]+(\.[0-9]{2})?$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,awardedIntegral: [
				      /^\d+$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,balePresaleNum: [
				      /^\d+$/
				      ,'请输入正确格式的数字且不能带空格'
				    ]
				    ,picpath: [
				      /\S{1,}/
				      ,'请上传商品图片'
				    ]
				    ,infoPicPath: [
				      /\S{1,}/
				      ,'请上传商品内容图片'
				    ]
				    
				    ,content: function(value){
				      layedit.sync(editIndex);
				    }
				  });
				  });
 			</script>
           <script type="text/javascript">
				 layui.config({
				  base:'http://localhost:8091/tvmallbs/layui/lay/mymodules/'
					}).use(["element", "layer",'croppers', "form", "table", "jquery"], function(){
					var elem = layui.element;
					var layer = layui.layer;
					var form = layui.form;
					var table = layui.table;
					var upload = layui.upload;
					var croppers = layui.croppers;
					var $ = layui.jquery;
						croppers.render({
			            elem: '#editimg1'
			            ,saveW:350     //保存宽度
			            ,saveH:350
			            ,mark:1/1    //选取比例
			            ,area:'900px'  //弹窗宽度
			            ,url: "BaleGoods/UploadPictures.do"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
			            ,done: function(data){ //上传完毕回调
			            	console.log(data);
			                $("#img").attr('src','<%=basePath %>view/viewPic.do?path='+data);
			                $("#gcPicpath").attr('value',data);
			               	
			            }
			            });
					//var id = ${selectGoodsClassDetil.gcId};
					//console.log(id);
					//layui.common.init();
					
		        		
});
</script>
    </body>

</html>
